#ifndef __LOG_H__
#define __LOG_H__

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdarg>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "singleton.h"

#include <log4cxx/logger.h>
#include <log4cxx/patternlayout.h>
#include <log4cxx/consoleappender.h>
#include <log4cxx/dailyrollingfileappender.h>

#define MSG_MAX_LEN 4096
#define LOG_FFL __FUNCTION__,__FILE__,__LINE__
#define LOG_INFO COM::logger->info
#define LOG_DEBUG COM::logger->debug
#define LOG_WARN COM::logger->warn
#define LOG_ERROR COM::logger->error 

class Logger
{
public:
  static void error(const char* pattern, ...);

  static void info(const char* pattern, ...);
private:
  static char msg_[MSG_MAX_LEN];
};


#define MSG_LEN 4096 
class qLogger
{
  public:
    qLogger(std::string& filename);
    ~qLogger();

    void setName(const std::string& filename);

    void addConsoleLog();
    void removeConsoleLog();
    void addLocalFileLog(const std::string& file);
    void removeLocalFileLog(const std::string& file);

    //void getMessage(const char* pattern);
    void info(const char* pattern, ...);
    void log(const char* pattern, ...);
    void debug(const char* pattern, ...);
    void warn(const char* pattern, ...);
    void error(const char* pattern, ...);
  private:
    std::string local_logname_;//日志文件位置

    log4cxx::LoggerPtr logger_;
    char message_[MSG_LEN];

    qMutex mt_;
};


#endif
